package com.qin.mall.controller;

import com.qin.mall.common.api.CommonResult;
import com.qin.mall.service.PmsSkuStockService;
import com.qin.mall.domain.PmsSkuStock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 产品库存Controller
 * @author Leisure
 * create 2022 2022/11/7 9:59
 **/
@RestController
@RequestMapping("/sku$")
public class SkuStockController {
    @Autowired
    private PmsSkuStockService skuStockService;

    // TODO 根据产品id和skuCode模糊搜索
    @GetMapping("/{pid}")
    public CommonResult<List<PmsSkuStock>> getStock(@PathVariable Long pid,
                                                    @RequestParam(value = "keyword",required = false) String keyword){
        List<PmsSkuStock> info = skuStockService.getList(pid, keyword);
        return CommonResult.success(info);
    }

   
    
    @PostMapping("/update$/{pid}")
    public CommonResult updateStock(@PathVariable Long pid,
            @RequestBody List<PmsSkuStock> skuStockList){
        int count = skuStockService.stockUpdate(pid,skuStockList);
        if(count>0){
            return CommonResult.success(count);
        }else{
            return CommonResult.failed();
        }

    }
}
